<template>
    <div class="postauthority">
        <pagetitle type="2"></pagetitle>
        <el-card class="pageCard">
            <div class="postmanagerTopTip">
                <img src="@/assets/image/teamhand.png" alt="" srcset="" class="gangweiTipimg" />
                <div>
                    <div class="topTip">团队的组织架构，方便您团队的管理和决策</div>
                    <div class="bottomTip">团队信息仅用于进行登记，不会泄露您的任何证件信息</div>
                </div>
            </div>
        </el-card>
        <el-card ref="pagecard">
            <el-table :data="tableData" style="width: 100%; margin-bottom: 20px" row-key="id" :indent="100" default-expand-all>
                <el-table-column prop="limits" label="岗位权限">
                    <template #default="scope">
                        <el-checkbox v-model="scope.row.checked" :disabled="scope.row.disabled" :indeterminate="scope.row.indeterminate" @change="change(scope.row)">
                            <span class="names" style="font-size: 12px">
                                {{ scope.row.limits }}
                            </span>
                        </el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column prop="explain" label="权限说明" />
                <el-table-column prop="grade" label="高危管理等级" width="200">
                    <template #default="scope">
                        <el-icon v-for="item in scope.row.grade" color="#F54347"><StarFilled /></el-icon>
                    </template>
                </el-table-column>
                <el-table-column prop="beAuthorized" label="已授权管理岗位" width="300" />
            </el-table>
        </el-card>
    </div>
</template>
<script lang="ts" setup>
import { ref, reactive } from "vue";
import { ParentDict } from "@/utils/jurisdictionHandle";
const value = ref(5);
interface Tree {
    id: number;
    label: string;
    children?: Tree[];
}
const tableData = reactive([
    {
        limits: "团队管理",
        explain: "包括我的团队、团队管理、客户管理、供应商管理等。",
        grade: 0,
        beAuthorized: "",
        indeterminate: false,
        checked: false,
        disabled: false,
        id: 1,
        children: [
            {
                limits: "团队管理",
                explain: "包括成员管理、部门管理、授权管理绩效考核员工培训、资质技能等。",
                grade: 0,
                beAuthorized: "",
                indeterminate: false,
                checked: false,
                disabled: false,
                id: 11,
                children: [
                    {
                        limits: "团队认证",
                        explain: "包括输入法定代表人信息、统一社会信用代码、组织机构类型、产业分类、联系人信息及团队位置等。",
                        grade: 5,
                        beAuthorized: "",
                        indeterminate: false,
                        checked: false,
                        disabled: false,
                        id: 111,
                        children: [
                            {
                                limits: "申请认证",
                                explain: "第一次提交团队的认证申请。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1111,
                            },
                            {
                                limits: "修改认证",
                                explain: "修改后提交团队的认证申请。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1112,
                            },
                        ],
                    },
                    {
                        limits: "成员管理",
                        explain: "包括查看成员、删除成员、邀请成员 等功能。",
                        grade: 0,
                        beAuthorized: "",
                        indeterminate: false,
                        checked: false,
                        disabled: false,
                        id: 112,
                        children: [
                            {
                                limits: "查看成员",
                                explain: "查看 本部门 成员详情。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1121,
                            },
                            {
                                limits: "邀请成员",
                                explain: "发起 邀请成员，并邀请。",
                                grade: 3,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1122,
                            },
                            {
                                limits: "审核成员",
                                explain: "发起 成员审核 功能 。",
                                grade: 3,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1123,
                            },
                            {
                                limits: "删除成员",
                                explain: "发起  删除成员 功能 。",
                                grade: 5,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1124,
                            },
                        ],
                    },
                    {
                        limits: "部门管理",
                        explain: "",
                        grade: 0,
                        beAuthorized: "",
                        indeterminate: false,
                        checked: false,
                        disabled: false,
                        id: 113,
                        children: [
                            {
                                limits: "查看成员",
                                explain: "查看 本部门 成员情况。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1131,
                            },
                            {
                                limits: "调入成员",
                                explain: "从 成员列表 中调入成员到本部门，请谨慎操作。",
                                grade: 3,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1132,
                            },
                            {
                                limits: "增减、修改部门",
                                explain: "加一层、删除 或 修改 部门，请谨慎操作。",
                                grade: 5,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1133,
                            },
                        ],
                    },
                    {
                        limits: "岗位管理",
                        explain: "",
                        grade: 0,
                        beAuthorized: "",
                        indeterminate: false,
                        checked: false,
                        disabled: false,
                        id: 114,
                        children: [
                            {
                                limits: "查看",
                                explain: "查看 本部门 岗位情况。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1141,
                            },
                            {
                                limits: "管理",
                                explain: "管理 本部门 岗位情况。",
                                grade: 0,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1142,
                            },
                            {
                                limits: "增减、修改",
                                explain: "加一层、删除 或 修改 部门，请谨慎操作。",
                                grade: 5,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1143,
                            },
                            {
                                limits: "新增岗位",
                                explain: "设置 岗位权限，新增岗位 操作。",
                                grade: 5,
                                beAuthorized: "",
                                indeterminate: false,
                                checked: false,
                                disabled: false,
                                id: 1144,
                            },
                        ],
                    },
                    {
                        limits: "授权管理（待开发）",
                        explain: "包括我的团队、团队管理、客户管理、供应商管理等。",
                        grade: 0,
                        beAuthorized: "",
                        indeterminate: false,
                        checked: false,
                        disabled: true,
                        id: 115,
                    },
                ],
            },
        ],
    },
]);
const dict = new ParentDict(tableData);
const change = (item: any) => {
    recursion(item);
    // let parent: any = dict.getPid(item.id);
    iteration(item);
};
const recursion = (item: any) => {
    if (item.children && item.children.length > 0) {
        item.indeterminate = false;
        item.children.forEach((v: any) => {
            if (!v.disabled) {
                v.checked = item.checked;
            }
            if (v.children && v.children.length > 0) {
                setTimeout(() => {
                    recursion(v);
                }, 10);
            }
        });
    }
};
const iteration = (item: any) => {
    let parent: any = dict.getPid(item.id);
    if (parent) {
        if (!item.children || item.length == 0) {
            if (dict.areObjectsEqual(parent.children, "checked", true)) {
                parent.indeterminate = false;
                parent.checked = true;
            } else if (dict.areObjectsEqual(parent.children, "checked", false)) {
                parent.indeterminate = false;
                parent.checked = false;
            } else {
                parent.indeterminate = true;
                parent.checked = false;
            }
        } else {
            if (dict.areObjectsEqual(parent.children, "checked", true)) {
                parent.indeterminate = false;
                parent.checked = true;
            } else if (dict.areObjectsEqual(parent.children, "checked", false)) {
                if (dict.areObjectsEqual(parent.children, "indeterminate", true)) {
                    parent.indeterminate = true;
                    parent.checked = false;
                } else if (dict.areObjectsEqual(parent.children, "indeterminate", false)) {
                    parent.indeterminate = false;
                    parent.checked = false;
                } else {
                    parent.indeterminate = true;
                    parent.checked = false;
                }
            } else {
                parent.indeterminate = true;
                parent.checked = false;
            }
        }
        setTimeout(() => {
            iteration(parent);
        }, 100);
    }
};
</script>
<style scoped lang="scss">
.pageCard {
    margin-bottom: 20px;
    .postmanagerTopTip {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .gangweiTipimg {
            width: 56px;
            height: 56px;
            margin-right: 25px;
        }
        .topTip {
            font-size: 16px;
            color: #333333;
            span {
                color: #23b14d;
                margin-left: 10px;
                cursor: pointer;
            }
        }
        .bottomTip {
            font-size: 14px;
            color: #666666;
            margin-top: 10px;
        }
    }
    .names {
        font-size: 12px !important;
    }
}
</style>
